//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类;

public class demo_1768 {
    public demo_1768() {
    }

    public static void main(String[] args) {
    }

    public static String mergeAlternately(String word1, String word2) {
        StringBuilder sb = new StringBuilder();
        if (word1.length() > word2.length()) {
            for(int i = 0; i < word2.length(); ++i) {
                sb.append(word1.charAt(i));
                sb.append(word2.charAt(i));
            }

            sb.append(word1.substring(word2.length()));
            return sb.toString();
        } else if (word2.length() > word1.length()) {
            for(int i = 0; i < word1.length(); ++i) {
                sb.append(word1.charAt(i));
                sb.append(word2.charAt(i));
            }

            sb.append(word2.substring(word1.length()));
            return sb.toString();
        } else {
            for(int i = 0; i < word1.length(); ++i) {
                sb.append(word1.charAt(i));
                sb.append(word2.charAt(i));
            }

            return sb.toString();
        }
    }

    public static String mergeAlternately2(String word1, String word2) {
        int n = word1.length();
        int m = word2.length();
        StringBuilder sb = new StringBuilder();

        for(int i = 0; i < n || i < m; ++i) {
            if (i < n) {
                sb.append(word1.charAt(i));
            }

            if (i < m) {
                sb.append(word2.charAt(i));
            }
        }

        return sb.toString();
    }
}
